package com.base.git;

import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/git/command")
public class GitCommandController {

    @Autowired
    private GitCommandService gitCommandService;

    @PostMapping("/createJsonFile")
    public void createJsonFile(@RequestBody @Valid CreateJsonFileRequest request) {
        gitCommandService.createJsonFile(request.getBranch(),request.getJson());
    }

    @GetMapping("/getBranchList")
    public List<String> getBranchList() throws Exception {
        return gitCommandService.getBranchList();
    }

    @PostMapping("/pull")
    public void pull(@RequestBody @Valid GitPullRequest request) throws Exception {
        gitCommandService.pull(request.getBranch());
    }

    @PostMapping("/getHistoryList")
    public List<String> getHistoryList(@RequestBody @Valid GetHistoryListRequest request) throws Exception {
        return gitCommandService.getHistoryList(request.getBranch());
    }

    @PostMapping("/getFileNameList")
    public List<String> getFileContent(@RequestBody @Valid GeFileNameListRequest request) throws Exception {
        return gitCommandService.getFileNameList(request.getBranch());
    }

    @PostMapping("/getFileContent")
    public String getFileContent(@RequestBody @Valid GeFileContentRequest request) throws Exception {
        return gitCommandService.getFileContent(request.getBranch(), request.getFileName());
    }

}
